package com.meixiang.adapter;

import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;

import com.meixiang.R;
import com.meixiang.activity.homes.insurance.InsuranceDetailsActivity;

import java.util.List;

/**
 * Created by Administrator on 2016/5/6.
 * 已购的保单和历史保单
 */
 public class InsuranceBuyAdapter extends RecyclerView.Adapter<InsuranceBuyAdapter.MyViewHolder> {

    private List<String> data ;
    private Context context ;

    public InsuranceBuyAdapter(Context context, List<String> data){
        this.data = data ;
        this.context = context ;
    }


    @Override
    public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        MyViewHolder myViewHolder = new MyViewHolder(LayoutInflater.from(context).inflate(R.layout.insurance_buy_adapter_item, parent, false));
        return myViewHolder;
    }

    @Override
    public void onBindViewHolder(MyViewHolder holder, int position) {
        if(position>=1){
            RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) holder.ll_total_parent.getLayoutParams();
            params.setMargins(0, 0,0, 0);
            holder.ll_total_parent.setLayoutParams(params);
        }
    }

    @Override
    public int getItemCount() {

        return data.size();
    }

    class MyViewHolder extends RecyclerView.ViewHolder {
        RelativeLayout ll_parent ;
        LinearLayout ll_total_parent ;
        public MyViewHolder(View itemView) {
            super(itemView);
            ll_parent = (RelativeLayout) itemView.findViewById(R.id.rl_parent);
            ll_total_parent = (LinearLayout) itemView.findViewById(R.id.ll_total_parent);
            ll_parent.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    context.startActivity(new Intent(context,InsuranceDetailsActivity.class));
                }
            });
        }
    }
}